import { Controller, Post, Body, Param, Patch, Delete } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Result } from 'src/common/Result';
import { CreateTabCollectionDto } from './dto/createTabCollection.dto';
import { NewWorkspaceInfo } from './dto/newWorkspaceInfo.dto';
import { TabCollectionService } from './tab-collection.service';

@ApiTags('tabCollection')
@Controller('tabCollection')
export class TabCollectionController {
  constructor(private readonly tabCollectionService: TabCollectionService) {}

  @Post('/:workspaceId')
  async create(
    @Body() createTabCollectionDto: CreateTabCollectionDto,
    @Param('workspaceId') workspaceId: string,
  ): Promise<Result> {
    await this.tabCollectionService.create(
      createTabCollectionDto.tabs,
      workspaceId,
      createTabCollectionDto.name,
    );
    return {
      message: '操作成功',
    };
  }

  @Patch('/:tabCollectionId')
  async move(
    @Body() newSpaceInfo: NewWorkspaceInfo,
    @Param('tabCollectionId') cid: string,
  ): Promise<Result> {
    try {
      await this.tabCollectionService.modify(cid, newSpaceInfo.newWorkspaceId);
      return {
        message: '操作成功',
      };
    } catch (error) {}
  }

  @Delete('/:id')
  remove(@Param('id') id: string) {
    return this.tabCollectionService.remove(id);
  }

  // @Get()
  // findAll() {
  //   return this.tabCollectionService.findAll();
  // }

  // @Get(':id')
  // findOne(@Param('id') id: string) {
  //   return this.tabCollectionService.findOne(+id);
  // }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateTabCollectionDto: UpdateTabCollectionDto) {
  //   return this.tabCollectionService.update(+id, updateTabCollectionDto);
  // }
}
